﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;

namespace PizzaWic.admin
{
    /// <summary>
    /// Permet de créer un cuisinier en base
    /// </summary>
    public partial class AddCooker : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            
            SqlAccess sql = new SqlAccess();
            DataSet data = sql.getLoginFree(this.login.Text);
            if (data.Tables[0].Rows.Count != 1)
               this.addCooker();
            Response.Redirect("CookerManagement.aspx");
        }

        private void addCooker()
        {
            String passwordCrypted = FormsAuthentication.HashPasswordForStoringInConfigFile(this.password.Text, "MD5");
            
            SqlAccess sqlAccess = new SqlAccess();
            Object[] data = new Object[4];
            data[0] = this.name.Text;
            data[1] = this.surname.Text;
            data[2] = this.login.Text;
            data[3] = passwordCrypted;
            sqlAccess.addCooker(data);
        }
    }
}